﻿#include "camview.h"
#include "ui_camview.h"

camview::camview(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::camview)
{
    ui->setupUi(this);
    viewfinder = new QCameraViewfinderEx(this);
    this->setWindowTitle("Cam");
    this->ui->CamLayout->addWidget(viewfinder);
    connect(this,SIGNAL(close_message()),parent,SLOT(on_camview_closed()));
}

camview::~camview()
{
    delete ui;
    m_Instance = nullptr;
}

camview* camview::GetInstance(QWidget *parent)
{
    if(m_Instance == nullptr)
    {
        m_Instance = new camview(parent);
    }
    return m_Instance;
}

void camview::setupviewfinder(QCamera* cam)
{
    cam->setViewfinder(viewfinder);
}

void camview::closeEvent(QCloseEvent *event)
{
    qDebug()<<"CamView Window Closed.";
    emit close_message();
    event->accept();
}

camview* camview::m_Instance = nullptr;
